﻿
/* -----------------------------------------
*  定义对话窗口功能
*  
*
*
*--------------------------------------------*/
YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(function () {
    // Define various event handlers for Dialog
    var handleSubmit = function () {
        var editwindow = document.getElementById("EditUIWindow");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
    };

    var handleCancel = function () {
        this.cancel();
    };
    var handleSubmit1 = function () {
        var editwindow = document.getElementById("EditUIWindow1");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
        }
        YAHOO.example.container.dialog2.hide();
    }
    var handleSuccess = function (o) {
        var response = o.responseText;
        response = response.split("<!")[0];
        document.getElementById("resp").innerHTML = response; fnSetField();
    };

    var handleFailure = function (o) {
        alert("Submission failed: " + o.status);
    };

    var handleSubmitDataEdit = function () {
        var editwindow = document.getElementById("UIWindowDataEdit");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
    }

    var handleSubmitImport = function () {
        var editwindow = document.getElementById("UIWindowImport");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
    }

    var handleSubmitVerify = function () {
        var editwindow = document.getElementById("UIWindowVerify");
        if (editwindow) {
            editwindow.contentWindow.Save();
        }
    }

    // Remove progressively enhanced content class, just before creating the module
    YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");

    /*
    数据编辑
    */
    YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
							    { width: const_EditWindowWidth,
							        height: const_EditWindowHeight,
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "保存", handler: handleSubmit, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });
    /*
    
    */
    YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
							    { width: "420px",
							        height: "400px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "保存", handler: handleSubmit1, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });

    /*
    
    */
    YAHOO.example.container.dialog3 = new YAHOO.widget.Dialog("dialog3",
							    { width: "350px",
							        height: "90px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "确定", handler: DeleteData, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });

    /*
    查询
    */
    YAHOO.example.container.dialog4 = new YAHOO.widget.Dialog("dialog4",
							    { width: "650px",
							        height: "350px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [
							    { text: "取消", handler: handleCancel}]
							    });
    YAHOO.example.container.dialog5 = new YAHOO.widget.Dialog("dialog5",
							    { width: const_EditWindowWidth,
							        height: const_EditWindowHeight,
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [
							    { text: "取消", handler: handleCancel}]
							    });

	YAHOO.example.container.dialogDataEdit = new YAHOO.widget.Dialog("dialogDataEdit",
							    {
							        width: "300px",
							        height: "240px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "保存", handler: handleSubmitDataEdit, isDefault: true }, { text: "取消", handler: handleCancel}]
							    });

    YAHOO.example.container.dialogImport = new YAHOO.widget.Dialog("dialogImport",
							    {
							        width: "450px",
							        height: "350px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "导入", handler: handleSubmitImport, isDefault: true }, { text: "取消", handler: handleCancel }]
							    });

    YAHOO.example.container.dialogVerify = new YAHOO.widget.Dialog("dialogVerify",
	                            {
	                                width: "600px",
	                                height: "400px",
	                                fixedcenter: true,
	                                visible: false,
	                                draggable: true,
	                                close: true,
	                                autofillheight: "body",
	                                constraintoviewport: true,
	                                buttons: [{ text: "保存", handler: handleSubmitVerify, isDefault: true }, { text: "取消", handler: handleCancel }]
	                            });
    // Validate the entries in the form to require that both first and last name are entered


    // Wire up the success and failure handlers
    YAHOO.example.container.dialog1.callback = { success: handleSuccess,
        failure: handleFailure
    };

    // Render the Dialog
    YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.render();
    YAHOO.example.container.dialog3.render();
    YAHOO.example.container.dialog4.render();
    YAHOO.example.container.dialog5.render();
    YAHOO.example.container.dialogDataEdit.render();
    YAHOO.example.container.dialogImport.render();
    YAHOO.example.container.dialogVerify.render();

    /* 对话框
    ****/
    //----------------------------------------------------*/
    // YAHOO.util.Event.addListener("btnAddNew", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);



    //拖动大小
    var resize = new YAHOO.util.Resize("dialog1", {
        handles: ["br"],
        autoRatio: false,
        minWidth: 450,
        minHeight: 400,
        status: false
    });
    resize.on("startResize", function (args) {

        if (this.cfg.getProperty("constraintoviewport")) {
            var D = YAHOO.util.Dom;

            var clientRegion = D.getClientRegion();
            var elRegion = D.getRegion(this.element);

            resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
        } else {
            resize.set("maxWidth", null);
            resize.set("maxHeight", null);
        }

    }, YAHOO.example.container.dialog1, true);
    resize.on("resize", function (args) {
        var panelHeight = args.height;
        this.cfg.setProperty("height", panelHeight + "px");
    }, YAHOO.example.container.dialog1, true);

    //拖动大小
    SetResize("dialogDataEdit", 450, 400, YAHOO.example.container.dialogDataEdit);
    SetResize("dialogImport", 450, 400, YAHOO.example.container.dialogImport);
    SetResize("dialogVerify", 450, 400, YAHOO.example.container.dialogVerify);
});

var SetResize = function (vDialog, vMinWidth, vMinHeight, objDialog) {

    var resize = new YAHOO.util.Resize(vDialog, {
        handles: ["br"],
        autoRatio: false,
        minWidth: vMinWidth,
        minHeight: vMinHeight,
        status: false
    });

    resize.on("startResize", function (args) {
        if (this.cfg.getProperty("constraintoviewport"))
        {
            var D = YAHOO.util.Dom;
            var clientRegion = D.getClientRegion();
            var elRegion = D.getRegion(this.element);

            resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
        }
        else 
        {
            resize.set("maxWidth", null);
            resize.set("maxHeight", null);
        }
    }, objDialog, true);

    resize.on("resize", function (args) {
        var panelHeight = args.height;
        this.cfg.setProperty("height", panelHeight + "px");
    }, objDialog, true);
}


